<?php
session_start();

if(!isset($_SESSION['logged_in_admin']))
{
	header ("Location: login.php");
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>
			The Cobra Snake - ADMIN
		</title>
		<style type="text/css">
			body 
			{ 
				font-family:Verdana, Geneva, sans-serif; font-size:13px; color:#333;
			} 
			#photographerList
			{
				list-style: none; 
				margin: 0; 
				padding: 0; 
				border: none;
			}
			
			#photographerList li
			{
				width:300px;
				cursor: pointer; 
				margin-bottom: 3px;
			}
			
			.active
			{
				background:#eee url('js/jquery.plupload.queue/img/done.gif') no-repeat right top; 
				color:#000;
			}
			
			.inactive
			{
				background:#ccc url('js/jquery.plupload.queue/img/error.gif') no-repeat right top; 
				color:#666;
			}
			.saving
			{
				background:#ccc url('js/jquery.plupload.queue/img/throbber.gif') no-repeat right top; 
				color:#333;
			}
		</style>
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
		<script type="text/javascript" src="../js/functions.js"></script>
	</head>
	<body>
		<div class="topLinks"><a href="./" target="_self">DONE</a> <a href="./logout.php" target="_self"> LOG OUT</a></div>
		<div id="new_pass_form">
			<form action="">
				<h1>TO ADD A PHOTOGRAPHER OR RESET THE PHOTOGRAPHER'S PASSWORD ENTER THEIR EMAIL BELOW:</h1>
				<label for="email" id="name_label">Email</label>  
				<input type="text" name="email" id="email"></input>  
		    	<label class="error" for="email" id="email_error">This field is required.</label> 
				<input type="submit" value="SUBMIT" class="button" />
				<img id="submitstatus" src='js/jquery.plupload.queue/img/throbber.gif' border="0"/>
			</form>
		</div>
		<div id='message'></div>
		<h2>Current Photographers:</h2>
		<div id='legend'><span class='active'>ACTIVE LOGIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;<span class='inactive'>DEACTIVATED LOGIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div><br />
		<ul id="photographerList"></ul>
		
		<script type="text/javascript">
			$(function() 
			{  
				$('.error').hide();  
				$('#submitstatus').hide();
				$(".button").click(function() 
				{  
					// validate and process form here  
					
					$('.error').hide();  
					
					$('#submitstatus').show();
					
					var email = $("input#email").val();
					if (email == "") 
					{  
					  $("label#email_error").show();  
					  $("input#email").focus();  
					  return false;  
					}
					
					webservice.photos.makeNewPhotographerLogin( email, function( photograperList )
					{
						$("input#email").val('');
						$('#message').text("User will receive email with temp password.");
						setTimeout(function() { $('#message').fadeOut(); }, 3000);
						showPhotographers();
					});
					
					
						
					return false; 
				
				}); 
				
				$("#photographerList li").live("click", function()
				{
					if($(this).attr('class') == "active")
					{
						var targetListItem = $(this);
						$(this).removeClass("active");
						$(this).addClass("saving");
						webservice.photos.setPhotographerActiveStatus( $(this).attr("rel"), "0",  function( msg )
						{
							targetListItem.removeClass("saving");
							targetListItem.addClass("inactive");					
						});
					}else
					{
						var targetListItem = $(this);
						$(this).removeClass("inactive");
						$(this).addClass("saving");
						webservice.photos.setPhotographerActiveStatus( $(this).attr("rel"), "1",  function( msg )
						{
							targetListItem.removeClass("saving");
							targetListItem.addClass("active");					
						});
					}
				  
				});
				
			  
				showPhotographers();
			   
			});
			
			function showPhotographers()
			{
				webservice.photos.getPhotographerList( function( photograperList )
				{
					var jList = $("#photographerList");
					
					jList.html("");
					
					
	
					// Loop over each value in the array.
					$.each(photograperList, function(intIndex, objValue)
					{
						var activeStatusClass = (objValue.active == '1')? "active": "inactive";
						
						jList.append( $("<li class='"+activeStatusClass+"' rel='" + objValue.id + "'>" + objValue.email + "</li>") );
						
					});
					
					$('#submitstatus').hide();
						
				});
			}
		</script>

	</body>

</html>